﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Microsoft.Practices.Unity;
using System.Collections.ObjectModel;
using Hallenberg.SmartClient.Interfaces;

namespace Hallenberg.SmartClient.Menu
{
    /// <summary>
    /// Used to compose menu items into hierarchies
    /// when using MenuItemAttribute in derived frameworks.
    /// </summary>
    public class MenuItemContainer : MenuItem
    {
        public const string MenuManagerRootId = "{B296039B-4B12-41f9-A789-0D4BB726A6AF}";

        /// <summary>
        /// Initializes a new instance of the <see cref="MenuManager"/> class.
        /// </summary>
        public MenuItemContainer(string menuItemName)
            : base(MenuManagerRootId, menuItemName, string.Empty, MenuItemDisabledPolicy.Hide)
        {
        }

        /// <summary>
        /// Inserts the menu item.
        /// </summary>
        /// <param name="menuItem">The menu item.</param>
        /// <param name="afterMenuItemId">The after menu item id. If null, the menu item is added last in the list.</param>
        /// <returns>True if menu was inserted correct.</returns>
        public bool AddMenuItem(MenuItem menuItem)
        {
            Debug.Assert(menuItem != null);
            if (menuItem == null)
            {
                throw new ArgumentNullException("menuItem");
            }

            this.ChildItems.Add(menuItem);
            this.ChildItems.Sort();

            return true;
        }
    }
}
